"""
相关配置信息
1数据库配置
2redis配置
3session配置
4csrf配置

"""
from datetime import timedelta
from flask import Flask,session
from flask_sqlalchemy import SQLAlchemy
from redis import StrictRedis
from flask_session import Session
from config import Config
from flask_wtf.csrf import CSRFProtect

#讲初始化信息抽取到单独文件，方便统一管理
app = Flask(__name__)



#加载配置类
app.config.from_object(Config)

#创建SQLAlchemy对象,关联app
db = SQLAlchemy(app)


#创建redis对象
redis_store = StrictRedis(host=Config.REDIS_HOST,port=Config.REDIS_PORT,decode_responses=True)

#创建Session对象，读取APP中session配置信息
Session(app)

#使用csrfprotect保护app  #四种方式'POST', 'PUT', 'PATCH', 'DELETE'
CSRFProtect(app)

@app.route("/")
def hello():

    #测试redis存取数据
    redis_store.set("name","laowang")
    print(redis_store.get("name"))

    #测试session存取
    session["name"] = "zhangsan"
    print(session.get("name"))

    return "hello"


if __name__ == '__main__':
    app.run()